<template>
  <div style="width:100%;overflow-x:hidden">
    <weui-cell :list="cell_list" @on-click="on_cell_click">
    </weui-cell>
  </div>
</template>

<script>
  import WeuiCell from '../vue2componentSet/src/components/WeuiCell'
  import global from '../lib/global'
  import axios from 'axios'

  export default {
    components: {
      WeuiCell
    },
    data() {
      return {
        cell_list: [],
        url: ''
      }
    },
    mounted() {
      this.$store.commit('setTitle', 'cache')
      location.hash.split('?')[1] && location.hash.split('?')[1].split('&').forEach(kv => {
        kv.split('=')[1] && (this[kv.split('=')[0]] = decodeURIComponent(kv.split('=')[1]))
      })

      if (!this.url) {
        this.$router.goback()
        return
      }

      if (global.is_debug) {
        this.cell_list.push({
          value: '2017-01-01',
          link: 'https://zoro.site/1.cache'
        })
        return
      }
      axios.post(global.server + 'getCache.do', {
        url: this.url
      }).then(result => {
        var resObj = result.data
        if (resObj.result == -1) {
          this.$store.commit('toast', {
            type: 'warn',
            content: resObj.msg
          })
          //this.$router.goback()
          return
        }
        resObj.caches.forEach(item => {
          this.cell_list.push({
            value: item.cache_date,
            link: 'https://zoro.site/' + item.id + '.cache'
          })
        })
      }, err => {
        console.log(err)
      })
    },
    methods: {
      on_cell_click(index) {

      }
    }
  }
</script>
